/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Vacancy;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author MrChinh
 */
public class ListVacancy {

    ConnectDB myConn = new ConnectDB();
    Connection conn;
    public List<Vacancy> getListVacancy() {
        List<Vacancy> listV = new ArrayList<Vacancy>();
        try {
            conn = myConn.getConnect();
            Statement stmt  = conn.createStatement();
            String sql = "SELECT * FROM Vacancy";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                Vacancy vacancy = new Vacancy();
                vacancy.setVancancyId(rs.getString(1));
                vacancy.setCategoryId(rs.getString(2));
                vacancy.setInforId(rs.getInt(3));
                vacancy.setCompanyId(rs.getInt(4));
                vacancy.setTitle(rs.getString(5));
                vacancy.setPosition(rs.getString(6));
                vacancy.setWorkType(rs.getString(7));
                vacancy.setCreateDate(rs.getDate(8).toString());
                vacancy.setNumberRequirement(rs.getInt(9));
                vacancy.setSalary(Float.parseFloat(rs.getString(10)));
                vacancy.setDescription(rs.getString(11));
                vacancy.setEntitlement(rs.getString(12));
                vacancy.setYearOfExperience(rs.getInt(13));
                vacancy.setSkillRequirement(rs.getString(14));
                vacancy.setDegree(rs.getString(15));
                vacancy.setGender(rs.getString(16));
                vacancy.setRequirementAge(rs.getString(17));
                vacancy.setProfile(rs.getString(18));
                vacancy.setDeadline(rs.getDate(19).toString());
                vacancy.setSubmissionforms(rs.getString(20));
                vacancy.setStatus(rs.getInt(21));
                listV.add(vacancy);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listV;
    }
    
    public Vacancy getVacancy(String vId) {
        Vacancy vacancy = new Vacancy();
        try {
            conn = myConn.getConnect();
            Statement stmt  = conn.createStatement();
            String sql = "SELECT * FROM Vacancy V WHERE V.VacancyID = '" + vId + "'";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                vacancy.setVancancyId(rs.getString(1));
                vacancy.setCategoryId(rs.getString(2));
                vacancy.setInforId(rs.getInt(3));
                vacancy.setCompanyId(rs.getInt(4));
                vacancy.setTitle(rs.getString(5));
                vacancy.setPosition(rs.getString(6));
                vacancy.setWorkType(rs.getString(7));
                vacancy.setCreateDate(rs.getDate(8).toString());
                vacancy.setNumberRequirement(rs.getInt(9));
                vacancy.setSalary(Float.parseFloat(rs.getString(10)));
                vacancy.setDescription(rs.getString(11));
                vacancy.setEntitlement(rs.getString(12));
                vacancy.setYearOfExperience(rs.getInt(13));
                vacancy.setSkillRequirement(rs.getString(14));
                vacancy.setDegree(rs.getString(15));
                vacancy.setGender(rs.getString(16));
                vacancy.setRequirementAge(rs.getString(17));
                vacancy.setProfile(rs.getString(18));
                vacancy.setDeadline(rs.getDate(19).toString());
                vacancy.setSubmissionforms(rs.getString(20));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vacancy;
    }
}
